import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/net/response/entry_record_list_data.dart';

import '../../net/api/http_api.dart';

class EntryRecordModel extends BaseMvvmModel {
  @override
  void onCleared() {}

  Future<List<EntryRecordListData>> entryRecordList(
      {dynamic accessType,
      String intervieweeName = "",
      dynamic iotId,
      int page = 1,
      int rows = 20,
      String? visitDateEnd,
      String? visitDateStart,
      String? visitorName,
      dynamic accessHumanType,
      String? accessHumanName}) async {
    var url = "${HttpApi.baseUrl}welfareGateAccessRecord/accessRecordList";
    var map = {
      "accessType": accessType,
      "intervieweeName": intervieweeName,
      "iotId": iotId,
      "page": page,
      "rows": rows,
      "visitDateEnd": visitDateEnd,
      "visitDateStart": visitDateStart,
      "visitorName": visitorName,
      "accessHumanType": accessHumanType,
      "accessHumanName": accessHumanName,
    };
    var data = await HttpGo.instance.postData(url,
        data: map, options: Options(contentType: Headers.jsonContentType));
    if ("0" == data['code']) {
      return ((data['data']['rows'] as List?) ?? [])
          .map((e) => EntryRecordListData.fromJson(e))
          .toList();
    } else {
      throw data['msg'];
    }
  }

  Future<List<PickerDataWithIdModel>> equipmentList(
      {int type = 4, String source = 'local'}) async {
    var url = "${HttpApi.baseUrl}iotDevice/listBean";
    var map = {
      "type": type,
      "source": source,
    };
    var data = await HttpGo.instance.postData(url,
        data: map,
        options: Options(contentType: Headers.jsonContentType),
        queryParameters: {
          "wrapper": true,
        });
    if ("0" == data['code']) {
      return ((data['data']['rows'] as List?) ?? [])
          .map((e) => PickerDataWithIdModel(
              pickName: e['name'], pickId: e['id'].toString()))
          .toList();
    } else {
      throw data['msg'];
    }
  }


  ///门店列表
  Future<List<PickerDataWithIdModel>> gatePointList(
      {String  gateName = "", String uniqueNumber = ''}) async {
    var url = "${HttpApi.baseUrl}welfareGatePoint/getGatePointList";
    var map = {
      "gateName": gateName,
      "uniqueNumber": uniqueNumber,
      "wrapper": true,
    };
    var data = await HttpGo.instance.postData(url,
        data: map,
        options: Options(contentType: Headers.formUrlEncodedContentType),);
    if ("0" == data['code']) {
      return ((data['data']['rows'] as List?) ?? [])
          .map((e) => PickerDataWithIdModel(
          pickName: e['gatePosition'], pickId: e['id'].toString()))
          .toList();
    } else {
      throw data['msg'];
    }
  }
}
